package com.bwie.redkids.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import android.widget.TextView;

import com.bwie.redkids.R;
import com.bwie.redkids.bean.RecommendBean.MyBrand;
import com.bwie.redkids.view.HomeRecommendGridView_View;

public class RecommendBaseAdapter extends BaseAdapter implements ListAdapter {

	private Context context;
	private ArrayList<MyBrand> arrayList;

	public RecommendBaseAdapter(Context context, ArrayList<MyBrand> arrayList) {
		this.context = context;
		this.arrayList = arrayList;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return arrayList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return arrayList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = View.inflate(context, R.layout.recommend_list_item,
					null);
			holder.home5_title = (TextView) convertView
					.findViewById(R.id.home5_title);
			holder.home5_gridView = (HomeRecommendGridView_View) convertView
					.findViewById(R.id.home5_gridView);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.home5_title.setText(arrayList.get(position).getKey());
		HomeRecommendGridBaseAdapter adapter = new HomeRecommendGridBaseAdapter(
				context, arrayList.get(position).getValue());
		holder.home5_gridView.setAdapter(adapter);
		return convertView;
	}

	class ViewHolder {
		TextView home5_title;
		HomeRecommendGridView_View home5_gridView;
	}

}
